using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;


public partial class DealDuLich : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }

    private void LoadData()
    {
        tbLoaiSP loaiSP = tbLoaiSPBUS.GetId(6);
        int Total = 0;
        Criteria Cri = new Criteria();
        Cri.add(Condition.AND, tbSanPhamColumns.IdLoaiSP, Condition.EQUAL, loaiSP.IdLoaiSP.ToString());
        tbSanPhamCollection sanPhamCollection = tbSanPhamBUS.Get(Cri.Criter, PagerV2_8_1.CurrentIndex, PagerV2_8_1.PageSize,
                                                                 tbSanPhamColumns.IdLoaiSP.ToString(),
                                                                 OrderDirection.ASC.ToString(), out Total);
        repeater1.DataSource= sanPhamCollection;
        repeater1.DataBind();
        PagerV2_8_1.ItemCount = Total;
        if (PagerV2_8_1.ItemCount <= PagerV2_8_1.PageSize)
            PagerV2_8_1.Visible = false;
        else
            PagerV2_8_1.Visible = true;
    }

    protected void repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            tbSanPham sanPham = (tbSanPham)e.Item.DataItem;
            HyperLink hyp_tensp = (HyperLink)e.Item.FindControl("hyp_tensp");
            Literal lit_old = (Literal)e.Item.FindControl("lit_old");
            Literal lit_giaban = (Literal)e.Item.FindControl("lit_giaban");
            Literal lit_tietkiem = (Literal)e.Item.FindControl("lit_tietkiem");
            Literal lit_count = (Literal)e.Item.FindControl("lit_count");
            Image img_HinhAnh = (Image)e.Item.FindControl("img_HinhAnh");
            hyp_tensp.Text = sanPham.TenSP;
            lit_old.Text = sanPham.GiaTriThuc.ToString();
            lit_giaban.Text = sanPham.GiaBan.ToString();
            lit_count.Text = sanPham.SLDaBan.ToString();
            int tietkiem = sanPham.GiaTriThuc - sanPham.GiaBan;
            lit_tietkiem.Text = tietkiem.ToString();

            int Id = 0;
            int MaHA = tbHinhAnhBUS.FirstImage(int.Parse(sanPham.IdSanPham.ToString()), Id);
            if (MaHA > 0)
            {
                tbHinhAnh hinhAnh = tbHinhAnhBUS.GetById(MaHA);
                img_HinhAnh.ImageUrl = "~/Photos/" + hinhAnh.TenHinh.ToString();
            }
            else
            {
                img_HinhAnh.ImageUrl = "~/Photos/no_images.jpg";
            }
 
        }

    }
}
